package com.ymx.darling.generater;

import com.ymx.darling.generater.config.GlobalConfig;
import com.ymx.darling.generater.config.StrategyConfig;
import com.ymx.darling.generater.table.Table;

import java.util.List;

/**
 * Mapper生成器
 * @author 爱Java的小于
 */
public class MapperGenerator extends BaseGenerator {
    public MapperGenerator(GlobalConfig globalConfig, StrategyConfig strategyConfig) {
        super(globalConfig, strategyConfig);
    }

    public void createMapper(List<Table> tableList) {
        tableList.forEach(table -> {
            String className = this.toUpperCaseFirstOne(this.convertToCamelCase(table.getName()));
            String mapperContent = TemplateContent.getContent("mapper")
                .replaceAll("\\{basePackage\\}", globalConfig.getBasePackage())
                .replace("{author}", globalConfig.getAuthor())
                .replaceAll("\\{entity\\}", className);
            // 将创建好的类写入到文件中
            String filePath = String.format("%s\\%s\\%sMapper.java", this.getProjectAbsolutePath(), strategyConfig.getMapperPackageName(), className);
            this.createClass(filePath, mapperContent);
        });
    }
}
